﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MMITDomain.Abstract;
using MMITDomain.Entities;

namespace MMITDomain.Concrete
{
    public class EFChargeRepository : IChargeRepository
    {
        EFDbContext dbContext = new EFDbContext();
        
        #region IChargeRepository Members

        public IQueryable<Charge> Charges
        {
            get
            {
                return dbContext.Charges;
            }
        }

        public void SaveCharge(Charge objCharge)
        {
            if (objCharge.Id == 0)
            {
                dbContext.Charges.Add(objCharge);
            }

            dbContext.SaveChanges();
        }

        public void DeleteCharge(Entities.Charge ObjCharge)
        {
            dbContext.Charges.Remove(ObjCharge);

            dbContext.SaveChanges();
        }

        public Charge GetChargeById(int iChargeId)
        {
            return dbContext.Charges.Find(iChargeId);
        }

        public IQueryable<Charge> GetChargesByTransactionType(TransactionTypes enumTransactionType)
        {
            var charges = from p in dbContext.Charges
                          where p.TransactionTypeId == (int)enumTransactionType
                          select p;
            
            return charges;
        }
        #endregion
    }
}
